/**
 * Copyright (c) 2014-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#pragma once

#include <openr/common/Types.h>
#include <openr/common/Util.h>
#include <openr/config/Config.h>

namespace {

// utility function to construct thrift::AreaConfig
openr::thrift::AreaConfig
createAreaConfig(
    const std::string& areaId,
    const std::vector<std::string>& neighborRegexes,
    const std::vector<std::string>& interfaceRegexes) {
  openr::thrift::AreaConfig areaConfig;
  areaConfig.set_area_id(areaId);
  areaConfig.set_neighbor_regexes(neighborRegexes);
  areaConfig.set_include_interface_regexes(interfaceRegexes);
  return areaConfig;
}

openr::thrift::OpenrConfig
getBasicOpenrConfig(
    const std::string nodeName = "",
    const std::string domainName = "domain",
    const std::vector<openr::thrift::AreaConfig>& areaCfg = {},
    bool enableV4 = true,
    bool enableSegmentRouting = false,
    bool orderedFibProgramming = false,
    bool dryrun = true) {
  openr::thrift::LinkMonitorConfig linkMonitorConfig;
  *linkMonitorConfig.include_interface_regexes_ref() =
      std::vector<std::string>{".*"};
  *linkMonitorConfig.redistribute_interface_regexes_ref() =
      std::vector<std::string>{"lo1"};

  openr::thrift::KvstoreConfig kvstoreConfig;

  openr::thrift::SparkConfig sparkConfig;
  *sparkConfig.hello_time_s_ref() = 2;
  *sparkConfig.keepalive_time_s_ref() = 1;
  *sparkConfig.fastinit_hello_time_ms_ref() = 50;
  *sparkConfig.hold_time_s_ref() = 2;
  *sparkConfig.graceful_restart_time_s_ref() = 6;

  openr::thrift::OpenrConfig config;

  *config.node_name_ref() = nodeName;
  *config.domain_ref() = domainName;
  config.enable_v4_ref() = enableV4;
  config.enable_segment_routing_ref() = enableSegmentRouting;
  config.enable_ordered_fib_programming_ref() = orderedFibProgramming;
  config.dryrun_ref() = dryrun;

  *config.kvstore_config_ref() = kvstoreConfig;
  *config.link_monitor_config_ref() = linkMonitorConfig;
  *config.spark_config_ref() = sparkConfig;

  *config.enable_rib_policy_ref() = true;

  if (areaCfg.empty()) {
    config.set_areas({createAreaConfig(kTestingAreaName, {".*"}, {".*"})});
  } else {
    config.set_areas(areaCfg);
  }

  return config;
}

} // namespace
